package com.itcm.skymail.cart.vo;

import java.math.BigDecimal;
import java.util.List;

/**
 * 描述: 购物车信息封装
 *
 * @author cm_fighting
 * @create 2020-11-22 7:08 下午
 */
public class Cart {
    private List<CartItem> items;

    // 商品总个数
    private Integer countNum;

    // 商量项数量
    private Integer countType;

    // 商品总价
    private BigDecimal totalAmount;

    // 优惠价格
    private BigDecimal reduce = new BigDecimal("0.00");

    public List<CartItem> getItems() {
        return items;
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
    }

    // todo : 待测试
    public Integer getCountNum() {
        int count = 0;
        if (this.items != null && this.items.size() > 0) {
            count = this.items.stream().mapToInt(CartItem::getCount).sum();
        }
        return count;
    }


    public Integer getCountType() {
        int count = 0;
        if (this.items != null && this.items.size() > 0) {
            count = this.items.size();
        }
        return count;
    }


    public BigDecimal getTotalAmount() {
        BigDecimal amount = new BigDecimal("0.00");
        if (this.items != null && this.items.size() > 0) {
            for (CartItem item : items) {
                amount = amount.add(item.getTotalPrice());
            }
        }
        return amount.subtract(this.reduce);
    }


    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
